package com.ja.openchat.viewmodels;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ja.openchat.ui.contact.EditUserProfileActivity;
import com.zy.openchat.core.manager.TgEvent;
import com.zy.openchat.core.model.user.UserInfo;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.base.BaseViewModel;


public class EditUserProfileViewModel extends BaseViewModel {

    private EditUserProfileActivity editUserProfileActivity;

    public EditUserProfileViewModel(@NonNull Application application, BaseModel mRepository) {
        super(application);
    }



    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onTgEvent(final TgEvent tg_event) {
        switch (tg_event.event) {
            case EUser_Td_UpdateContactInfo:
            case EUser_Td_Contact_Photo_Ok: {
                UserInfo updateUser = (UserInfo) tg_event.data;
                if (updateUser != null && updateUser instanceof UserInfo) {
                    if (editUserProfileActivity.user != null && editUserProfileActivity.user.id == updateUser.id) {
                        editUserProfileActivity.user = updateUser;
                        //请求原始联系人信息
                        editUserProfileActivity.requestOrgUserInfo();
                        //刷新页面
                        editUserProfileActivity.resetUI();
                    }
                }
            }
            break;
        }
    }


    public void setContext(EditUserProfileActivity editUserProfileActivity) {
        this.editUserProfileActivity = editUserProfileActivity;
    }
}
